/***************************************************
> Copyright (C) 2024 ==ASD== All rights reserved.
> File Name: userID.c
> Author: asd
> Mail:3319941451@qq.com 
> Created Time: 2024年12月03日 星期二 14时55分23秒
***************************************************/
#include "user.h"

//USER*ICincome(USER*head){
//	USER*head = NULL;
	displayMenu();
	
  //  	return head;
//}
void displayMenu()
{
	int choice = 0;
	while (1) {
	printf("\n===ID卡充值界面===\n");
	printf("1.充值\n");
	printf("2.");
	printf("2.查看余额\n");
	printf("3.查看积分\n");
	printf("4.退出\n");
        scanf("%d", &choice);
 	
	
	USER*head = NULL;
        switch (choice) {
            case 1:
		head = activity(head);
                break;
            case 2:
		head = usewater(head);
                break;
            case 3: 
               	head = view(head);
                break;
            case 4:
              	head =  integral(head);
                break;
            case 5:
                freeLink(head);
                exit(0);
            default:
                printf("无效的选项。\n");
        }

}

float  income(USER*head)
{
	float money = 0 ;
	char confirm = 0;
	USER*user = NULL;
	user = head;
	printf("\n---ID卡充值界面---\n");
	printf("输入充值金额\n");
	scanf("%.2f",&money);
	if(money>=0&&money<= MAX)
	{
	   // 询问用户是否确认充值  
        printf("确认充值%.2f元吗？(y/n) ");  
        scanf(" %c", &confirm);  
        // 检查用户是否确认充值  
        if (confirm == 'y' || confirm == 'Y') 
		{  
            // 执行充值操作  
           activity(head);
			printf("充值成功!\n");  
        } else 
		{  
            printf("充值取消。\n");  
        }  
    } 
    printf("感谢使用充值系统！\n");
	}
}
// 执行充值操作  
USER* activity(USER*head){ 
	USER*user = head;
	user = head;
    	// 获取当前时间
    	time_t rawtime;
    	time(&rawtime);
    
    	// 将时间转换为本地时间结构体
   	 struct tm * timeinfo;
    	timeinfo = localtime(&rawtime);
    
    	// 从本地时间结构体中提取年、月、日信息
    	int month = timeinfo->tm_mon + 1;    // tm_mon是从0开始计数的（0代表1月），所以需要加1
        int day = timeinfo->tm.mday;
	//活动1
	if(month== 3 && day<= 29 && day>=15)
	{
		user->thing.money+income(head)*1.2;
	}
	//活动2
	if(income(head)>=0&&income(head)<=200)
	{
		user->thing.money+income(head);
	}
	 if(income(head)>=200)
	 {
		user->thing.money+income(head)+20;
	 }else if(income(head)>=500)
	 {
		user->thing.money+income(head)+80;
	}else
	 {
		user->thing.money+income(head)+100;
}
	return head;
}
USER* view(USER*head)
{
	char id[20] = {0};
	USER*temp = NULL;
	USER*user = NULL;
	printf("input id:\n");	
	scanf("%s",id);
	user = head->next;	
	//查询是否存在
	while(user !=NULL)
	{
		if(user->id == id)
		{
			temp = user;
			printf("输出IC卡中的金额:%.2f\n",user->thing.money);
			break;
		}
		user = user->next;
	}
	
	if(user == NULL)
	{
		printf("not find\n");
	}
	if(user->thing.money <=20)
{
		printf("余额不足，请尽快充值。\n");
}
	return head;
}
USER* integral(USER*head)
{
	USER*user = NULL;
	user = head;
	int integral = 0;
	integral = (int)income(head)/10;
	user->thing.integral = integral;
	printf("%d",user->thing.integral);

	return head;

}

USER*deliverWater(USER*head)
{
	
	USER*user = NULL;
	user = head;
	if(user->thing.integral >=200)
	{
		printf("会员，可享受送水服务\n");
		float water = 0;
		int cost_water = 0;
		int cost_people = 0;
		printf("输入想要送的水量\n");
		scanf("%.2f",&water);
	
		cost_water = water/3; 
		cost_people = water/5;
		user->thing.money -= cost_water+cost_people;

	}else
	{
		printf("还不是会员，请继续积累积分\n");
	}
}
USER* jifenduhuanshangping(USER*head)
{
	int integral = 0;
	USER*user = NULL;
	user = head;
	integral = shopping();
	user->thing.integral -=integral;

	return head;
}
USER* yongwater(USER*head){
	char confirm; 
	float cost = 0;
	USER*user = NULL;
	user = head;
	printf("是否要接水(y/n)\n");
	scanf("%c",&confirm);
	if(confirm == 'y'|| confirm == 'Y')
	{
		float water = 0;
		printf("");
		scanf("%.2f",&water);
		if((int)(water-30) <= 0)
		{
		cost = water/3; 
		}else if((int)(water-200) <= 0)
		{
		cost = water/2; 
		}else
		{
		cost = water;
		}
		if(user->thing.money>cost)
		{
			user->thing.money -= cost;
			printf("取水完成，共接了%.2f水,共花费%.2f",water,cost);
			
		}else{
			printf("余额不足，请尽快充值。\n");
		}
		
		return head;
	}
	
/*void freeLink(USER *head)
{
	USER*temp = NULL;
	while(head->next !=NULL)
	{
		temp = head->next;
		free(head);
		head = head->next;
	}
}*/
	

